package cn.jinjimi.base.util;

import android.os.CountDownTimer;
import android.widget.Button;

/**
 * 倒计时
 * Created by HANER on 15/4/1.
 */
public class TimeCount extends CountDownTimer {
    private Button button;

    public TimeCount(Button button, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);//参数依次为总时长,和计时的时间间隔
        this.button = button;
    }

    @Override
    public void onFinish() {//计时完毕时触发
        cancel();
        button.setText("重新获取");
        button.setEnabled(true);
    }

    @Override
    public void onTick(long millisUntilFinished) {//计时过程显示
        button.setEnabled(false);
        button.setText(millisUntilFinished / 1000 + "s");
    }
}
